﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace Web.Components
{
    public sealed class ShoppingCartItem
    {
        /// <summary>
        /// 商品Id
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 分类
        /// </summary>
        public string CategoryCode { get; set; }

        /// <summary>
        /// 商品名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 变体Id
        /// </summary>
        public Guid VariantId { get; set; }

        /// <summary>
        /// 变体名称
        /// </summary>
        public string VariantName { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal UnitPrice { get; set; }

        /// <summary>
        /// 小计
        /// </summary>
        public decimal SubTotal { get { return UnitPrice * Quantity - Discount; } }

        /// <summary>
        /// 折扣
        /// </summary>
        public decimal Discount
        {
            get
            {
                var amount = 0M;
                if (Discounts != null && Discounts.Count > 0)
                {
                    amount = Discounts.Sum(o => o.Value);
                }
                return amount * Quantity;
            }
        }

        /// <summary>
        /// 属性
        /// </summary>
        public string AttributeInfo { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int Quantity { get; set; }

        /// <summary>
        /// 重量
        /// </summary>
        public decimal Weight { get; set; }

        /// <summary>
        /// 库存数量
        /// </summary>
        public int Stock { get; set; }

        /// <summary>
        /// 订单中可购买最小数量
        /// </summary>
        public int OrderMinQuantity { get; set; }

        /// <summary>
        /// 订单中可购买最大数量
        /// </summary>
        public int OrderMaxQuantity { get; set; }

        /// <summary>
        /// 扩展信息
        /// </summary>
        public string Extra { get; set; }
        /// <summary>
        /// 信息
        /// </summary>
        public string Message { get; set; }

        public IDictionary<int, decimal> Discounts { get; set; }

        public ShoppingCartItem()
        {
            Discounts = new Dictionary<int, decimal>();
            OrderMaxQuantity = int.MaxValue;
            OrderMinQuantity = 0;
            Quantity = 1;
        }
    }
}